home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / WINPROGS.ARJ / OWNSIZE.C < prev    next >
Text File  |  1991-01-13  |  5KB  |  192 lines

  1. /*   OwnSize.c   -  OwnSize and Profile Program
  2.                     Norton and Yao
  3. */
  4.  
  5. #include <windows.h>
  6.  
  7. #define REOPEN_NORMAL   0
  8. #define REOPEN_ZOOM     1
  9. #define REOPEN_DEFAULT  2
  10.  
  11.  
  12. static char szAppName[] = "ownsize";
  13. char achPr[]   = "OWNSIZE";
  14. char achFile[] = "WIN.INI";
  15.  
  16.  
  17. long FAR PASCAL WndProc  (HWND, WORD, WORD, LONG);
  18.  
  19. int PASCAL WinMain (HANDLE hInstance,
  20.                     HANDLE hPrevInstance,
  21.                     LPSTR  lpszCmdParam,
  22.                     int    nCmdShow)
  23.                     
  24.   {
  25.   HWND        hwnd;
  26.   MSG         msg;
  27.   WNDCLASS    wndclass;
  28.   int         x, y, cx, cy;
  29.   int         iReopen;  
  30.  
  31.   if (!hPrevInstance)
  32.     {      
  33.      wndclass.style            = NULL;
  34.      wndclass.lpfnWndProc      = WndProc;
  35.      wndclass.cbClsExtra       = 0;
  36.      wndclass.cbWndExtra       = 0;
  37.      wndclass.hInstance        = hInstance;
  38.      wndclass.hIcon            = LoadIcon (hInstance, szAppName);
  39.      wndclass.hCursor          = LoadCursor (hInstance, szAppName);
  40.      wndclass.hbrBackground    = COLOR_WINDOW + 1;
  41.      wndclass.lpszMenuName     = NULL;
  42.      wndclass.lpszClassName    = szAppName;
  43.      
  44.      RegisterClass(&wndclass);
  45.      
  46.      /*  for first instance only - set position & size to that of window
  47.                                    when last ran.                           */
  48.                                    
  49.  
  50.      cy = GetSystemMetrics (SM_CYSCREEN) -
  51.           GetSystemMetrics (SM_CYICON)   -
  52.          (GetSystemMetrics (SM_CYCAPTION) * 2);                                   
  53.          
  54.      x = GetPrivateProfileInt (achPr, "x", 0, achFile);
  55.      y = GetPrivateProfileInt (achPr, "y", 0, achFile);
  56.      
  57.      cx = GetSystemMetrics (SM_CXSCREEN);
  58.      cx = GetPrivateProfileInt (achPr, "cx", cx, achFile);
  59.      cy = GetPrivateProfileInt (achPr, "cy", cy, achFile);
  60.      
  61.      iReopen = GetPrivateProfileInt (achPr, "Reopen", 0, achFile);
  62.      
  63.      if (iReopen == REOPEN_ZOOM)
  64.        nCmdShow = SW_SHOWMAXIMIZED;
  65.      
  66.      if (iReopen == REOPEN_DEFAULT)
  67.        {
  68.        x  = CW_USEDEFAULT;
  69.        cx = CW_USEDEFAULT;
  70.        }   
  71.     }
  72.   else
  73.     {
  74.     x = cx = CW_USEDEFAULT;
  75.     y = cy = 0;
  76.     }   
  77.    
  78.  
  79.   
  80.   hwnd = CreateWindow (szAppName,
  81.                        "OwnSize and Profile Program",
  82.                        WS_OVERLAPPEDWINDOW,
  83.                        x,
  84.                        y,
  85.                        cx,
  86.                        cy,
  87.                        NULL,
  88.                        NULL,
  89.                        hInstance,
  90.                        NULL);
  91.                        
  92.                                                                                       
  93.   ShowWindow (hwnd, nCmdShow);
  94.  
  95. /*  UpdateWindow (hwnd);  */
  96.   
  97.   while (GetMessage (&msg, NULL, 0, 0))
  98.     {
  99.     TranslateMessage (&msg);
  100.     DispatchMessage  (&msg);
  101.     }
  102.     
  103.   return msg.wParam;
  104.   }
  105.   
  106. long FAR PASCAL WndProc (HWND hwnd,
  107.                          WORD message,
  108.                          WORD wParam,
  109.                          LONG lParam)
  110.                          
  111.   {
  112.   static int    xLeft;
  113.   static int    yTop;
  114.   static int    cxWidth;
  115.   static int    cyHeight;
  116.   
  117.   
  118.   switch (message)
  119.     {
  120.     case WM_MOVE:
  121.       if (IsZoomed (hwnd))
  122.         return 0;
  123.       
  124.       xLeft =  LOWORD (lParam);
  125.       xLeft -= GetSystemMetrics (SM_CXFRAME);
  126.       
  127.       yTop  = HIWORD (lParam);
  128.       yTop -= (GetSystemMetrics (SM_CYFRAME) + 
  129.                GetSystemMetrics (SM_CYCAPTION) - 1);
  130.       
  131.       break;
  132.                
  133.      case WM_SIZE:
  134.        if (IsZoomed (hwnd))
  135.          return 0;
  136.   
  137.        cxWidth  = LOWORD (lParam);
  138.        cxWidth += 2 * GetSystemMetrics (SM_CXFRAME);
  139.        
  140.        cyHeight  = HIWORD (lParam);
  141.        cyHeight += (2 * GetSystemMetrics (SM_CYFRAME) + 
  142.                         GetSystemMetrics (SM_CYCAPTION) - 1);
  143.        break;
  144.                         
  145.  
  146.     case WM_DESTROY:
  147.       {
  148.       char ach[80];
  149.       int  iReopen;
  150.  
  151.       /*  Update private ownsize entry  */
  152.       
  153.       wsprintf (ach, "%d", xLeft);
  154.       WritePrivateProfileString (achPr, "x", /*  X.  */
  155.                                  ach, achFile);
  156.                                  
  157.       wsprintf (ach, "%d", yTop);                           
  158.       WritePrivateProfileString (achPr, "y", /*  Y.  */
  159.                                  ach, achFile);
  160.  
  161.       if (cxWidth == 0)
  162.         cxWidth = CW_USEDEFAULT;
  163.       
  164.       wsprintf (ach, "%u", cxWidth);
  165.       WritePrivateProfileString (achPr, "cx", /*  CX.  */
  166.                                  ach, achFile);
  167.         
  168.       wsprintf (ach, "%d", cyHeight);
  169.       WritePrivateProfileString (achPr, "cy", /*  CY.  */
  170.                                  ach, achFile);
  171.  
  172.       /*  write  reopen flags  for iconic/zoomed windows  */
  173.       iReopen = REOPEN_NORMAL;
  174.       if (IsZoomed (hwnd)) 
  175.         iReopen = REOPEN_ZOOM;
  176.       if (IsZoomed (hwnd)) 
  177.         iReopen = REOPEN_DEFAULT;
  178.          
  179.       wsprintf (ach, "%d", iReopen);
  180.       WritePrivateProfileString (achPr, "Reopen", ach, achFile);
  181.          
  182.       PostQuitMessage (0);
  183.       }
  184.       break;
  185.     
  186.     default:  return (DefWindowProc (hwnd, message, wParam, lParam));
  187.               break;
  188.     }
  189.     return 0L;
  190.     
  191.   }                  
  192.